<?php

class ErrorController extends Fengqiaoju_Controller_Action {

	public function errorAction1() {

		$type = 'error';
		$layout = new Zend_Layout ();
		$layout->setLayoutPath ( APPLICATION_PATH . '/layouts/scripts' );
		$layout->setLayout ( 'error' );
		$this->view->title = '信息提示 ' . $type;
		$this->view->type = $type;
		$this->view->goUrl = $goUrl;
		$layout->content = '咕~~(╯﹏╰)b ，网页暂时打了个盹儿。<br>这样的错误伤不起啊！管理员发现了有没有！！！！';
		echo $layout->render ();
		exit ();
	}

	public function errorAction() {

		$this->view->title = '页面有错误 _ error';
		$errors = $this->_getParam ( 'error_handler' );
		
		if (! $errors) {
			$this->view->message = 'You have reached the error page';
			return;
		}
		
		switch ($errors->type) {
			case Zend_Controller_Plugin_ErrorHandler :: EXCEPTION_NO_ROUTE :
			case Zend_Controller_Plugin_ErrorHandler :: EXCEPTION_NO_CONTROLLER :
			case Zend_Controller_Plugin_ErrorHandler :: EXCEPTION_NO_ACTION :
				
				// 404 error -- controller or action not found
				$this->getResponse ()->setHttpResponseCode ( 404 );
				$this->view->message = 'Page not found';
				break;
			default :
				// application error
				$this->getResponse ()->setHttpResponseCode ( 500 );
				$this->view->message = 'Application error';
				break;
		}
		
		// Log exception, if logger available
		if ($log = $this->getLog ()) {
			$log->crit ( $this->view->message, $errors->exception );
		}
		
		// conditionally display exceptions
		if ($this->getInvokeArg ( 'displayExceptions' ) == true) {
			$this->view->exception = $errors->exception;
		}
		
		$this->view->request = $errors->request;
	}

	public function getLog() {

		$bootstrap = $this->getInvokeArg ( 'bootstrap' );
		if (! $bootstrap->hasResource ( 'Log' )) {
			return false;
		}
		$log = $bootstrap->getResource ( 'Log' );
		return $log;
	}

}

